package net.goutalk.glcs.module.erpModel.caseErpCustomer.controller;

import net.goutalk.glcs.common.annotation.GlcsLog;
import net.goutalk.glcs.common.constant.GlobalConstant;
import net.goutalk.glcs.common.model.result.R;
import net.goutalk.glcs.module.erpModel.caseErpCustomer.dto.AddCaseErpCustomerContactsDto;
import net.goutalk.glcs.module.erpModel.caseErpCustomer.dto.UpdateCaseErpCustomerContactsDto;
import net.goutalk.glcs.module.erpModel.caseErpCustomer.entity.CaseErpCustomerContacts;
import net.goutalk.glcs.module.erpModel.caseErpCustomer.service.ICaseErpCustomerContactsService;
import net.goutalk.glcs.module.erpModel.caseErpLog.service.ICaseErpLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 客户联系人【case_erp_customer_contacts】 前端控制器
 * </p>
 *
 * @author hnyyzy
 * @since 2023-07-11
 */
@RestController
@RequestMapping(GlobalConstant.CASE_ERP_CUSTOMER +"/caseErpCustomerContacts")
@Api(value = GlobalConstant.CASE_ERP_CUSTOMER +"/caseErpCustomerContacts", tags = "客户联系人")
@AllArgsConstructor
public class CaseErpCustomerContactsController {
    private ICaseErpCustomerContactsService caseErpCustomerContactsService;

    private ICaseErpLogService caseErpLogService;


    @PostMapping
    @ApiOperation(value = "新增客户联系人信息")
    public R add(@Valid @RequestBody AddCaseErpCustomerContactsDto dto) {
        return R.ok(caseErpCustomerContactsService.add(dto));
    }

    @PutMapping
    @ApiOperation(value = "修改客户联系人信息")
    public R update(@Valid @RequestBody UpdateCaseErpCustomerContactsDto dto) {
        return R.ok(caseErpCustomerContactsService.update(dto));
    }

    @GetMapping(value = "/info")
    @ApiOperation(value = "根据id查询客户联系人信息")
    public R info(@RequestParam Long id) {
        CaseErpCustomerContacts caseErpCustomerContacts = caseErpCustomerContactsService.getById(id);
        if (caseErpCustomerContacts == null) {
            R.error("找不到此客户联系人信息！");
        }
        return R.ok(caseErpCustomerContacts);
    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    @GlcsLog(value = "删除客户联系人信息")
    public R delete(@Valid @RequestBody Long id) {
        return R.ok(caseErpCustomerContactsService.removeById(id));
    }
}
